<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class transactionModel extends Model {
    protected $price;
    protected $time;
    protected $idPeople;
    protected $idProduct;
    
    public function setPrice($price) {
        $this->price = $price;
    }
    
    public function setTime($time) {
        $this->time = $time;
    }
    
    public function setidPeople($id) {
        $this->idPeople = $id;
    }
    
    public function setidProduct($id) {
        $this->idProduct = $id;
    }
    
    public function getPrice() {
        return $this->price;
    }
    
    public function getTime() {
        return $this->time;
    }
    
    public function getidPeople() {
        return $this->idPeople;
    }
    
    public function getidProduct() {
        return $this->idProduct;
    }
    
    
    public function storeToDB() {
        $sql = "INSERT INTO transaction
			(price, time, idProduct, idPeople)
			VALUES
			(?, ?, ?, ?
			 )";
        
        $data = array ($this->price, $this->time, $this->idProduct, $this->idPeople);
	$sth = $this->_db->prepare ( $sql );
	return $sth->execute ( $data );
    }
    
    public function getAllTransactionByIdProduct($id) {
        $sql = "SELECT *
                    FROM transaction 
                    WHERE idProduct = '$id'
                    ORDER BY price DESC
                    ";

        $this->_setSql($sql);
        $transactions = $this->getAll();
        if (empty($transactions)) {
            return false;
        }
        else
            return $transactions;
    }
}
?>
